#!/usr/bin/env python
import gtk

class QueryDialog(gtk.Dialog):
#===============================================================================
# A class to create an Ok/Cancel type dialog.  Inherits from 'gtk.Dialog'.
#===============================================================================

    # Creates the 'QueryDialog', setting the 'title' shown in the titlebar, 
    # 'icon' displayed, the 'message' shown in the box, and the 'parent' window. 
    def __init__(self,title="", icon=gtk.STOCK_DIALOG_INFO, 
                message="", parent=None):
        """ creates the controls and sets the message to be displayed """
        image=gtk.Image()
        image.set_from_stock(icon,gtk.ICON_SIZE_DIALOG)
        hbox=gtk.HBox()
        msg=gtk.Label(message)
        msg.wrap=True
        msg.width_chars=20
        retval=gtk.Dialog.__init__(self, title, parent,
                        gtk.DIALOG_MODAL |  gtk.DIALOG_DESTROY_WITH_PARENT,
                        (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT,
                        gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
        hbox.pack_start(image,False,False,5)
        hbox.pack_start(msg,False,False,5)
        self.vbox.pack_start(hbox,True,True,0)
        return retval
    
    # Show the dialog and call the 'run' method of the inherited 'gtk.Dialog'. 
    def run(self):
        """ runs the dialog, automagically calling the show_all() method """
        self.show_all()
        response=gtk.Dialog.run(self)
        retval=response == gtk.RESPONSE_ACCEPT
        return retval
    
class ErrorDialog(gtk.Dialog):
#===============================================================================
# A class to create an error dialog.  Inherits from 'gtk.Dialog'.
#===============================================================================

    # Creates the 'ErrorDialog', setting the 'title' shown in the titlebar, 
    # 'icon' displayed, the 'message' shown in the box, and the 'parent' window.
    def __init__(self,title="", icon=gtk.STOCK_DIALOG_ERROR, 
                message="", parent=None):
        """ creates the controls and sets the message to be displayed """
        image=gtk.Image()
        image.set_from_stock(icon,gtk.ICON_SIZE_DIALOG)
        hbox=gtk.HBox()
        msg=gtk.Label(message)
        msg.wrap=True
        msg.width_chars=20
        retval=gtk.Dialog.__init__(self, title, parent,
                        gtk.DIALOG_MODAL |  gtk.DIALOG_DESTROY_WITH_PARENT,
                        (gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
        hbox.pack_start(image,False,False,5)
        hbox.pack_start(msg,False,False,5)
        self.vbox.pack_start(hbox,True,True,0)
        return retval
    
    # Show the dialog and call the 'run' method of the inherited 'gtk.Dialog'. 
    def run(self):
        """ runs the dialog, automagically calling the show_all() method """
        self.show_all()
        response=gtk.Dialog.run(self)
        retval=response == gtk.RESPONSE_ACCEPT
        return retval
